home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1481.dms / var1481.adf / Extract_Me.LHA / misc / arrt2qrt.c < prev    next >
C/C++ Source or Header  |  1994-07-07  |  2KB  |  109 lines

  1. /***********************************************************
  2. *
  3. *    This file is Copyright © 1990-1994 Dan Wesnor
  4. *
  5. *    This file and any executables resulting from compilation
  6. *    of this file are freely distributable so long as the
  7. *    above copyright statement is included intact.  This
  8. *    statement of distributability is limited to this file
  9. *    only, and does not include any other file in this
  10. *    archive.
  11. *
  12. *    No gaurantees of usability are made for this file or
  13. *    any executables generated from it.  Use at your own risk.
  14. *
  15. ************************************************************
  16. *
  17. *    This program converts raw24 files as output by Magic
  18. *    camera to QRT format.  Use it as an examlpe of how
  19. *    to read or write raw24 files.
  20. *
  21. ***********************************************************/
  22.  
  23. #include <stdio.h>
  24. #include <fcntl.h>
  25. #include <stdlib.h>
  26.  
  27. far char     inbuff[8192*3],
  28.             red[8192], green[8192], blue[8192];
  29.  
  30.  
  31. void swapbytes(char *b)
  32. {
  33.     char    t;
  34.  
  35.     t = b[0];
  36.     b[0] = b[1];
  37.     b[1] = t;
  38. }
  39.  
  40.  
  41.  
  42.  
  43. main(int argc, char *argv[])
  44. {
  45.     int    x, y,
  46.         i, j,
  47.         ifh, ofh;
  48.     short    sx, sy, line;
  49.  
  50.     if (argc != 3)
  51.     {
  52.         printf("usage:  arrt2qrt in out\n");
  53.         exit(100);
  54.     }
  55.  
  56.     ifh = open(argv[1], O_RDONLY);
  57.     ofh = open(argv[2], O_WRONLY | O_CREAT);
  58.  
  59.     if ((ifh == -1) || (ofh == -1))
  60.     {
  61.         printf("arrt2qrt:  could not open files\n");
  62.         exit(100);
  63.     }
  64.  
  65.     read(ifh, &x, 4);
  66.     read(ifh, &y, 4);
  67.  
  68.     printf("image is %dx%d\n", x, y);
  69.  
  70.     sx = x;
  71.     sy = y;
  72.  
  73.     swapbytes((char *)&sx);
  74.     swapbytes((char *)&sy);
  75.  
  76.     write(ofh, &sx, 2);
  77.     write(ofh, &sy, 2);
  78.  
  79.     for (i=0; i<y; i++)
  80.     {
  81.         printf("working line %d\x0d", i);
  82.         fflush(stdout);
  83.  
  84.         line = i;
  85.         swapbytes((char *)&line);
  86.         write(ofh, &line, 2);
  87.  
  88.         read(ifh, inbuff, x*3);
  89.  
  90.         for (j=0; j<x; j++)
  91.         {
  92.             red[j] = inbuff[j*3];
  93.             green[j] = inbuff[j*3+1];
  94.             blue[j] = inbuff[j*3+2];
  95.         }
  96.  
  97.         write(ofh, red, x);
  98.         write(ofh, green, x);
  99.         write(ofh, blue, x);
  100.     }
  101.  
  102.     close(ofh);
  103.     close(ifh);
  104.  
  105.     printf("\ndone\n");
  106. }
  107.  
  108.  
  109.